#include<iostream>
#include<sstream>
#include<memory>
#include<string>
#include<jsoncpp/json/json.h>

int main()
{
  std::string str = R"({"姓名":"王五","年龄":24,"成绩":[71.1,60,50]})";
 
    Json::Value root;
    std::string err;
    Json::CharReaderBuilder crb;
    std::shared_ptr<Json::CharReader> read_ptr(crb.newCharReader());
    read_ptr->parse(str.c_str(), str.c_str() + str.size(), &root, &err);
 
    const char *name = root["姓名"].asCString();
    int age = root["年龄"].asInt();
    float grade[3] = {0};
    grade[0] = root["成绩"][0].asFloat();
    grade[1] = root["成绩"][1].asFloat();
    grade[2] = root["成绩"][2].asFloat();
 
    std::cout << name << std::endl;
    std::cout << age << std::endl;
    for (auto e : grade)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;


  //const char* name="小王";
  //int age=20;
  //float score[]={90.5,88.8,77.7};
  //Json::Value root;
  //root["姓名"]=name;
  //root["年龄"]=age;
  //for(int i=0;i<3;i++)
  //{
    //root["成绩"].append(score[i]);
  //}

  //Json::StreamWriterBuilder swb;
  //std::unique_ptr<Json::StreamWriter> sw(swb.newStreamWriter());
  //std::stringstream ss;
  //sw->write(root,&ss);
  //std::cout<<ss.str()<<std::endl;
  return 0;
  }
